package com.correo.vista.server.windows.componentes.paneles;

import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import com.correo.database.beans.CasillaCorreoBean;
import com.correo.database.beans.IBean;
import com.correo.database.beans.OfficeBean;
import com.correo.database.beans.UserBean;
import com.correo.exceptions.server.RefreshException;
import com.correo.modelo.server.ModelServer;
import com.correo.vista.server.windows.AdministracionCorreo;
import com.correo.vista.server.windows.ventanasInternas.DialogUser;
import com.correo.vista.server.windows.ventanasInternas.DialogOficce;
import com.correo.vista.server.windows.ventanasInternas.DialogCasillaCorreo;

public class PanelToolBarServer {

	private JPanel					panelPrincipal;
	private JToolBar 				toolbarConnect;
	private JButton 				buttonConnect;
	private JToolBar				toolbarABM;
	private JButton					buttonAlta;
	private JButton					buttonBaja;
	private JButton					buttonModificacion;
	private JButton					buttonView;
	private JButton					buttonActualizar;
	//private JDesktopPane	desktopPane;
	//private ModelServer 	model;
	private AdministracionCorreo 	adminCorreo;
	private DialogUser			dialogUser;
	private DialogOficce			dialogOficce;
	private DialogCasillaCorreo				dialogCasillaCorreo;
	
	
	public PanelToolBarServer(JDesktopPane desktopPane,ModelServer model,AdministracionCorreo adminCorreo){
		//this.desktopPane=desktopPane;
		//this.model = model;
		this.adminCorreo = adminCorreo;
		createComponents();
		initComponents();
		initActions();
	}
	private void initActions() {
		//buttonAlta.addActionListener(new ActionAltaServer(model,dialogAddUserDB));
		
	}
	private void createComponents() {
		panelPrincipal = new  JPanel();
		toolbarConnect= new JToolBar();
		buttonConnect= new JButton();
		toolbarABM= new JToolBar();
		buttonAlta = new  JButton();
		buttonBaja = new  JButton();
		buttonModificacion = new  JButton();
		buttonView = new  JButton();
		buttonActualizar = new JButton();
		dialogUser = new DialogUser(new JFrame(),adminCorreo,true);
		dialogOficce = new DialogOficce(adminCorreo,true);
		dialogCasillaCorreo = new DialogCasillaCorreo(adminCorreo,true);
		//jPanel5.setBorder(BorderFactory.createLineBorder(Color.magenta, 5));
	}

	public JPanel getPanelToolbar(){
		return panelPrincipal;
	}
	private void initComponents() {

        toolbarConnect.setRollover(true);       
        toolbarConnect.setEnabled(false);
        buttonConnect.setFocusable(true);
        buttonConnect.setText("Connect");
        buttonConnect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonConnect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolbarConnect.add(buttonConnect);

        toolbarABM.setRollover(true);
        toolbarABM.setEnabled(false);
        
        buttonAlta.setFocusable(false);
        buttonAlta.setText("Alta");
        buttonAlta.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonBaja.setText("baja");
        buttonModificacion.setText("modificacion");
        buttonView.setText("ver");
        buttonActualizar.setText("Actualizar");
        buttonAlta.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolbarABM.add(buttonAlta);
        toolbarABM.add(buttonBaja);
        toolbarABM.add(buttonModificacion);
        toolbarABM.add(buttonView);
        toolbarABM.add(buttonActualizar);
        
        setActionListeners();
        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(panelPrincipal);
        panelPrincipal.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(toolbarConnect, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toolbarABM, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(399, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(toolbarConnect, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toolbarABM, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );



	}
	private void setActionListeners() {
		//buttonAlta.addActionListener(new ActionListenerAlta(adminCorreo,dialogAddUserDB));
		//buttonModificacion.addActionListener(new ActionListenerModificacion(adminCorreo,dialogAddUserDB));
		//buttonView.addActionListener(new ActionListenerView(adminCorreo,dialogAddUserDB));
	}
	public JButton getButtonAlta() {
		return buttonAlta;
	}
	public void setButtonAlta(JButton buttonAlta) {
		this.buttonAlta = buttonAlta;
	}
	public JButton getButtonBaja() {
		return buttonBaja;
	}
	public void setButtonBaja(JButton buttonBaja) {
		this.buttonBaja = buttonBaja;
	}
	public JButton getButtonModificacion() {
		return buttonModificacion;
	}
	public void setButtonModificacion(JButton buttonModificacion) {
		this.buttonModificacion = buttonModificacion;
	}
	public JButton getButtonView() {
		return buttonView;
	}
	public void setButtonView(JButton buttonView) {
		this.buttonView = buttonView;
	}

	public DialogOficce getDialogOffice(OfficeBean officeBean,boolean modify,boolean view) throws RefreshException, SQLException, ClassNotFoundException {
		
			dialogOficce.setdata(officeBean);
			dialogOficce.setEditable(modify,view);
	
		return dialogOficce;
	}
	public DialogOficce getDialogOffice() throws RefreshException, SQLException, ClassNotFoundException {
		return dialogOficce;
	}
	
	
	public DialogUser getDialogUser(UserBean user,boolean modify, boolean view){
		if(user!=null){
			dialogUser.setData(user);
		}
		dialogUser.setEditable(modify,view);
		return dialogUser;
	}
	public DialogCasillaCorreo getDialogCasillaCorreo(CasillaCorreoBean casilla, boolean modify, boolean view) throws RefreshException, SQLException, ClassNotFoundException{
		
		dialogCasillaCorreo.setData(casilla);		
		dialogCasillaCorreo.setEditable(modify, view);
		//List<IBean> lista = adminCorreo.getModel().getModelOficce().refresh();
//		dialogCasillaCorreo.cargarCombo(adminCorreo.getModel().getModelOficce().refresh());
//		dialogCasillaCorreo.setEditable(modify,view);
//		if(lista!=null){
//			Iterator<IBean> it=lista.iterator();
//			while(it.hasNext()){
//				
//			}
//		}
		return dialogCasillaCorreo;
	}
	/////////////////////Listener
	public void setActionListenerAlta(ActionListener actionListener) {
		buttonAlta.addActionListener(actionListener);
		
	}
	public void setActionListenerBaja(ActionListener actionListener) {
		buttonBaja.addActionListener(actionListener);
		
	}
	public void setActionListenerModificacion(ActionListener actionListener) {
		buttonModificacion.addActionListener(actionListener);
		
	}
	public void setActionListenerView(ActionListener actionListener) {
		buttonView.addActionListener(actionListener);
		
	}
	public void setActionListenerActualizar(ActionListener actionListener) {
		buttonActualizar.addActionListener(actionListener);
		
	}
	
	
	

}
